package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JsonResult;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
/**
 * 日报
 */
public class News extends BaseDomain{

    //日报标题
    private String title;

    //日报副标题
    private String subTitle;

    //日报封面
    private String coverUrl;

    //日报浏览量
    private Integer browseNum;

    //日报发布时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;

    //日报状态
    private Integer state = STATE_AUDIT;

    //日报内容
    private NewsContent newsContent;

    public static final int STATE_AUDIT = 1;//草稿
    public static final int STATE_RELEASE = 2;//发布
    public static final int STATE_REJECT = -1;//拒绝

    //封装后台日报管理待审核网页需要的数据
    public String getStateName(){
        String stateName = "";
        switch (state){
            case 1:stateName = "草稿"; break;
            case 2:stateName = "发布"; break;
            case -1:stateName = "拒绝"; break;
        }
        return stateName;
    }

    //封装后台日报管理待审核网页需要的数据
    public String getJson(){
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("subTitle",subTitle);
        map.put("coverUrl",coverUrl);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(releaseTime);
        map.put("releaseTime",simpleDateFormat.format(releaseTime));
        return JSON.toJSONString(map);
    }
}